package com.gxuwz.business.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.gxuwz.business.entity.RecMed;

@Repository("recMedDAO")
public class RecMedDAO extends BaseDaoImpl<RecMedDAO>{
	
	/**
	 * 添加
	 */
	public boolean save(RecMed recMed){
		boolean isSucceed = false;
		try{
			getHibernateTemplate().save(recMed);
			isSucceed = true;
		}catch(Exception e){
			e.printStackTrace();
		}
		return isSucceed;
	}
	
	/**
	 * 查询处编对应的药编
	 */
	public List<String> getAllMedId(String recipeId){
		String hql = "select medicineId from RecMed where recipeId = ?";
		try {
			return (List<String>) getHibernateTemplate().find(hql, recipeId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * 根据处编和药编查询药品数量及总价
	 */
	public RecMed findByRecMedId(String recipeId, String medId){
		String hql = "from RecMed where recipeId = ? and medicineId = ?";
		try {
			return (RecMed) getHibernateTemplate().find(hql, recipeId, medId).get(0);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * 根据处编查询其所有药品总价
	 */
	public List<Double> getFeeByRecId(String recipeId){
		String hql = "select medicineFee from RecMed where recipeId = ?";
		try {
			@SuppressWarnings("unchecked")
			List<Double> feeList = (List<Double>) getHibernateTemplate().find(hql, recipeId);
			return feeList;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return null;
	}


}
